# -*- coding: utf-8 -*-
class WarehousingEntry < ActiveRecord::Base
  has_many :warehousing_entry_details ,:dependent => :destroy  #级联删除子表
  has_many :warehousing_entry_hxes ,:dependent => :destroy  #级联删除子表
  #belongs_to :from_warehouse, :class_name => "Warehouse" , :foreign_key => :to_warehouse_id
  #belongs_to :to_warehouse, :class_name => "Warehouse" , :foreign_key => :to_warehouse_id
  belongs_to :warehouse
  belongs_to :employee
  belongs_to :order_type
  belongs_to :department
  belongs_to :company
  belongs_to :vendor
  #关联采购单
  belongs_to :purchase_order

  def self.findWarehousingEntries conditionsStr,conditionsHash,paramsHash
    find(
      :all,
      :conditions => [conditionsStr,conditionsHash],
      :include => [:purchase_order,:warehousing_entry_details],
      :offset => paramsHash[:offset],
      :limit => paramsHash[:limit],
      :order => 'warehousing_entries.updated_at DESC'
    )
  end

  def self.countWarehousingEntries conditionsStr,conditionsHash
    count(
      :all,
      :include => [:purchase_order,:warehousing_entry_details],
      :conditions => [conditionsStr,conditionsHash]
    )
  end

end
